<?

if (is_array($form->getGlobalErrors()) && sizeof($form->getGlobalErrors())>0){
	foreach ($form->getGlobalErrors() as $name => $error){
		$out["errors"]["global"][$name]=$error->getMessage();
	}
}


foreach ($form as $field){
	if ($field->hasError()){
		$out["errors"]["fields"][$field->getName()]=(string)$field->getError();
	}
}

echo json_encode($out);
